Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
@types/mime-types
Advanced tools
TypeScript definitions for mime-types
@types/mime-types is a TypeScript type definition package for the mime-types library. The mime-types library is used to work with MIME types, which are used to specify the nature and format of a document, file, or assortment of bytes. This package provides type definitions to ensure type safety and better development experience when using the mime-types library in TypeScript projects.
Lookup MIME Type
This feature allows you to look up the MIME type based on a file extension. In this example, the MIME type for a .txt file is retrieved.
const mime = require('mime-types');
const mimeType = mime.lookup('example.txt');
console.log(mimeType); // 'text/plain'
Lookup File Extension
This feature allows you to look up the file extension based on a MIME type. In this example, the file extension for 'text/plain' is retrieved.
const mime = require('mime-types');
const extension = mime.extension('text/plain');
console.log(extension); // 'txt'
Add Custom MIME Type
This feature allows you to define custom MIME types. In this example, a custom MIME type 'application/x-my-type' is defined for the file extension 'mytype'.
const mime = require('mime-types');
mime.define({'application/x-my-type': ['mytype']});
const mimeType = mime.lookup('file.mytype');
console.log(mimeType); // 'application/x-my-type'
The 'mime' package is a comprehensive MIME type utility library for Node.js. It provides similar functionalities to 'mime-types', such as looking up MIME types and extensions. However, 'mime' also includes additional features like defining custom types and loading types from files.
The 'mime-db' package is a database of MIME types. It is used as a dependency by both 'mime' and 'mime-types' packages. While it does not provide direct utility functions, it serves as a comprehensive source of MIME type information.
The 'file-type' package is used to detect the file type of a Buffer or Uint8Array. Unlike 'mime-types', which relies on file extensions, 'file-type' inspects the actual file content to determine its type, making it more accurate in certain scenarios.
npm install --save @types/mime-types
This package contains type definitions for mime-types (https://github.com/jshttp/mime-types#readme).
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/mime-types.
export function lookup(filenameOrExt: string): string | false;
export function contentType(filenameOrExt: string): string | false;
export function extension(typeString: string): string | false;
export function charset(typeString: string): string | false;
export namespace charsets {
const lookup: typeof charset;
}
export const types: { [key: string]: string };
export const extensions: { [key: string]: string[] };
These definitions were written by Gyusun Yeom.
FAQs
TypeScript definitions for mime-types
The npm package @types/mime-types receives a total of 2,213,618 weekly downloads. As such, @types/mime-types popularity was classified as popular.
We found that @types/mime-types demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.